package homework1;

import java.util.Arrays;

public class Student {
	public static void main(String[] args){
		String[] courses = new String[3];
		String[] students = new String[3];
		int[][] scores = new int[students.length][courses.length];
		students[0]="aa";
		students[1]="bb";
		students[2]="cc";
		courses[0]="java";
		courses[1]="c++";
		courses[2]="c#";
		scores[0][0]=50;
		scores[0][1]=60;
		scores[0][2]=65;
		scores[1][0]=30;
		scores[1][1]=80;
		scores[1][2]=52;
		scores[2][0]=57;
		scores[2][1]=82;
		scores[2][2]=24;
		avg("avg", "java", courses, scores, students);
		avg("avg", "aa", courses, scores, students);
		avg("sort","sum",courses,scores,students);
	}
	public static void avg(String type,String str,String[] courses,int[][] scores,String[] students){
		if(type.equals("avg")){
			int avgScore=0;
			for(int i=0;i<courses.length;i++){
				if(courses[i].equals(str)){
					for(int j=0;j<students.length;j++){
					//System.out.println(scores[i][j]);
						avgScore = avgScore+scores[j][i];
					}
					System.out.println((double)avgScore/3);
				}
				else if(students[i].equals(str)){
					for(int j=0;j<students.length;j++){
					//System.out.println(scores[i][j]);
						avgScore = avgScore+scores[i][j];
					}
					System.out.println((double)avgScore/3);
				}
			}
		}
		else if(type.equals("sort")){
			int[] sums = new int[students.length];
			if(str.equals("sum")){
				for(int i=0;i<students.length;i++){
					for(int j=0;j<courses.length;j++){
						sums[i]+=scores[i][j];
					}
				}
				String[] strs = new String[students.length];
				for(int i=0;i<students.length;i++){
					strs[i] =sums[i] + ":"+ students[i];
				}
				Arrays.sort(strs);
				System.out.println(Arrays.toString(strs));
			}
		}
	}
	
}
